#ifndef SOCKET_H
#define SOCKET_H

#include <QTcpServer>
#include <QTcpSocket>
#include <QDebug>

// 服务器类
class TcpServer : public QTcpServer
{
    Q_OBJECT

public:
    TcpServer(QObject *parent = nullptr) : QTcpServer(parent) {}

protected:
    void incomingConnection(qintptr socketDescriptor) override;

public slots:
    void onReadyRead();

    void onDisconnected();
};

// 客户端类
class TcpClient : public QObject
{
    Q_OBJECT

public:
    TcpClient(QObject *parent = nullptr);

public slots:
    void connectToServer();

    void sendData(const QByteArray &data);

    void onConnected();

    void onReadyRead();
    void onDisconnected();

private:
    QTcpSocket *socket;
};

#endif // SOCKET_H
